package cn.yiyuan.auth.service.imp;

import cn.yiyuan.auth.domain.Permission;
import cn.yiyuan.auth.mapper.PermissionMapper;
import cn.yiyuan.base.until.PageInfo;
import cn.yiyuan.org.query.DepQuery;
import cn.yiyuan.auth.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project system
 * @date 2023-10-28
 * @package cn.yiyuan.org.service.impl
 */
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public void insert(Permission permission) {

    }

    @Override
    public void delete(Serializable id) {

    }

    @Override
    public void update(Permission permission) {

    }

    @Override
    public List<Permission> getAll() {
        return permissionMapper.getAll();
    }

    @Override
    public Permission getById(Serializable id) {
        return null;
    }

//    @Override
//    public PageInfo<Permission> queryPage(DepQuery depQuery) {
//        Long total = permissionMapper.queryTotal(depQuery);
//        if (total !=0){
//            List<Permission> page = permissionMapper.queryPage(depQuery);
//            return new PageInfo<Permission>(page,total);
//        }
//        return null;
//    }

    @Override
    public PageInfo<Permission> queryPage(DepQuery depQuery) {
        //查询总条数
        Long total =  permissionMapper.queryTotal(depQuery);
        //查询分页  数据
        //享元模式
        if (total !=0){
            List<Permission> list = permissionMapper.queryPage(depQuery);
            return new PageInfo<Permission>(total,list);
        }
        return new PageInfo<Permission>();
    }

    @Override
    public void deleteAll() {
        permissionMapper.deleteAll();
    }

    @Override
    public List<Permission> queryAll() {
        return permissionMapper.getAll();
    }

    @Override
    public void patchDelete(List<Long> ids) {
        permissionMapper.patchDelete(ids);
    }

    @Override
    public List<String> getUserPermissionByUserId(Long id) {
        return permissionMapper.getPermissionByUserId(id);
    }
}
